﻿using Microsoft.AspNetCore.Mvc;
using yunbo.Model.BIW;
using yunbo.Repositorys.BIWRepositorys;

namespace yunbo.Controllers.BIWControllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class Wbd_kqController : Controller
    {
        Wbd_kqRepository wbd_KqRepository=new Wbd_kqRepository();

        [HttpGet("GetFYWbd_kq")]
        public IActionResult GetFYWbd_kq(int PageNumber, int PageSize)
        {
            FYwbd_kq fYwbd_Kq=wbd_KqRepository.GetfYwbd_Kq(PageNumber, PageSize);
            return Ok(fYwbd_Kq);
        }

        [HttpPost("AddWbd_kq")]
        public IActionResult AddWbd_kq(TJWbd_kq wbd_Kq)
        {
            // 获取当前时间，并格式化为字符串
            string currentTime = DateTime.Now.ToString("yyyyMMdd");

            // 生成一个四位随机数
            Random random = new Random();
            int randomNumber = random.Next(1000, 10000); // 生成1000到9999之间的随机数
            string randomNumberString = randomNumber.ToString("D4"); // 格式化为四位数字字符串

            // 组合当前时间和随机数生成ID
            string code = $"kq{currentTime}{randomNumberString}";
            Wbd_kq wbd_Kq1 = new Wbd_kq()
            {
                kq_code = code,
                kq_name = wbd_Kq.kq_name,
                kq_zt = 1,
                kq_mj = wbd_Kq.kq_mj,
                kq_ssck = wbd_Kq.kq_ssck,
                kq_kwsl = wbd_Kq.kq_kwsl,
                is_deleted = 1,
                bz = wbd_Kq.bz,
                create_by = wbd_Kq.create_by,
                create_time = DateTime.Now,
            };
            bool kq = wbd_KqRepository.AddWbd_kq(wbd_Kq1) > 0;
            return Ok(kq);
        }
        [HttpPut("UpdateWbd_kq")]
        public IActionResult UpdateWbd_kq(XGWbd_kq wbd_Kq)
        {
            Wbd_kq wbd_Kq1 = new Wbd_kq()
            {
                kq_id=wbd_Kq.kq_id,
                kq_code = wbd_Kq.kq_code,
                kq_name =wbd_Kq.kq_name,
                kq_mj = wbd_Kq.kq_mj,
                kq_ssck = wbd_Kq.kq_ssck,
                kq_kwsl = wbd_Kq.kq_kwsl,
                bz=wbd_Kq.bz,
                update_by=wbd_Kq.update_by,
                update_time = DateTime.Now,
            };
            bool kq = wbd_KqRepository.UpdateWbd_kq(wbd_Kq1) > 0;
            return Ok(kq);
        }
        [HttpPut("UpIsDel")]
        public IActionResult UpIsDel(int id)
        {
            bool kq = wbd_KqRepository.UpIsDeleted(id) > 0;
            return Ok(kq);
        }
        [HttpGet("Getcode")]
        public IActionResult Getcode(string code)
        {
            List<Wbd_kq> cd=wbd_KqRepository.Getcode(code);
            return Ok(cd);
        }
        [HttpPut("UpZt")]
        public IActionResult UpZt(int id ,int zt)
        {
            bool kq=wbd_KqRepository.UpZt(id, zt)>0;
            return Ok(kq);
        }
    }

}
